import { defineConfig } from 'vite';
import { resolve } from 'path';
import vue from '@vitejs/plugin-vue';

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// 版本兼容
import legacy from '@vitejs/plugin-legacy';

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    legacy()
  ],
  server: {
    host: true,
    proxy: {
      '/ureport': {
        // target: "http://47.116.20.243:9999",
        target: "http://47.98.174.239:9998",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/ureport/, '')
      }
    }
  },
  resolve: {
    alias: {
      '@': '/src',
      '/@/': `/${resolve(__dirname, 'src')}/`,
    }
  },
  build: {
    outDir: 'dist', // 指定输出文件夹为 dist，可根据需求修改
    rollupOptions: {
      onwarn: () => {
        return
      },
      output: {
        chunkFileNames: 'static/js/[name]-[hash].js',
        entryFileNames: 'static/js/[name]-[hash].js',
        assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
      },
    }
  },
  esbuild: {
    // 禁用 ESLint 检查
    legalComments: 'none'
  },
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler' // or "modern", "legacy"
      },
    },
  },
});